<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="style/css/login.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<section id="content">
    <!--头部-->
    <div class="content-header clearfix">
        <a href="javascript:;" class="current">登录</a>
        <a href="javascript:;">注册</a>
    </div>
    <!--内容-->
    <div class="content-body">
        <div class="dom" style="display: block;">
            <form action="#">
                <div class="s1">
                    <h4 style="color: #FFFFFF">学号</h4>
                    <input name="user" type="text" placeholder="请输入学号">
                </div>
                <div class="s1">
                    <h4 style="color: #FFFFFF">身份证后六位</h4>
                    <input name="pwd" type="password" placeholder="请输入身份证后六位">
                </div>
                <div class="s2">
                    <input type="checkbox">
                    <span style="color: #FFFFFF">记住密码</span>
                </div>
                <input type="submit" class="btn" value="登&nbsp;录">
            </form>
            <div class="dom-footer">
                <div class="login-another">
                    <span style="color: mediumorchid;">还没有注册帐号?</span>
                    <span style="color: darkblue;" id="changeReg" onclick="changeReg()">立即注册</span>
                </div>
            </div>
        </div>
        <div class="dom">
            <form action="#">
                <div class="s1">
                    <h4 style="color: #FFFFFF">姓名</h4>
                    <input name="phone" type="text" placeholder="请输入姓名">
                </div>
                <div class="s1">
                    <h4 style="color: #FFFFFF">学号</h4>
                    <input name="user" type="text" placeholder="请输入学号">
                </div>
                <div class="s1">
                    <h4 style="color: #FFFFFF">身份证后六位</h4>
                    <input name="pwd" type="text" placeholder="请输入身份证后六位">
                </div>
                <div class="s1">
                    <h4 style="color: #FFFFFF">手机号</h4>
                    <input name="user" type="text" placeholder="请输入手机号">
                </div>
                <div class="s1">
                    <h4 style="color: #FFFFFF">QQ</h4>
                    <input name="user" type="text" placeholder="请输入QQ号">
                </div>
                <input type="submit" class="btn" value="注&nbsp;册">
            </form>
        </div>
    </div>
</section>
<script type="text/javascript">
    window.onload = function () {
        // 1.1 获取需要的标签
        let as = document.getElementsByClassName('content-header')[0].getElementsByTagName('a');
        let contents = document.getElementsByClassName('dom');

        // 1.2 遍历
        for (let i = 0; i < as.length; i++) {
            // 1.2.1 取出单个对象
            let a = as[i];
            a.id = i;

            // 1.2.2 监听鼠标的移动事件
            a.onclick = function () {
                // 让所有的a的class都清除
                for (let j = 0; j < as.length; j++) {
                    as[j].className = '';
                    contents[j].style.display = 'none';
                }

                // 设置当前a的class
                this.className = 'current';
                // 从contents数组中取出对应的标签
                contents[this.id].style.display = 'block';
            }

        }
    }
    function changeReg() {
        let contents = document.getElementsByClassName('dom');
        contents[0].style.display = 'none';
        contents[1].style.display = 'block';
        document.getElementById("0").className = '';
        document.getElementById("1").className = 'current';
    }
</script>
</body>
</html>